import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapTest {
    public static void main(String[] args) {
        HashMap<String,String> hm=new HashMap<>();
        //添加数据
        hm.put("a","A");
        String put = hm.put("a", "B");
        System.out.println(put);

        System.out.println("--------获取元素-------");
        //第一种方式
        System.out.println("--------获取元素方式1.get-------");
        String val = hm.get("a");
        System.out.println(val);
        //第二种方式
        System.out.println("--------获取元素方式2.keySet-------");
        hm.put("b", "B");
        hm.put("c", "C");
        hm.put("d", "D");
        hm.put("e", "E");
        //获取HashMap的所有元素
        Set<String> keys = hm.keySet();
        for(String key:keys){
            String value = hm.get(key);
            System.out.println(key+"----"+value);
        }
        System.out.println("--------获取元素方式3.entrySet方法-------");
        Set<Map.Entry<String, String>> entries = hm.entrySet();
        for(Map.Entry<String, String> entry:entries ){
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"-------"+value);
        }

        System.out.println("------并集操作------");
        HashMap<String,String> hm2=new HashMap<>();
        hm2.put("f","F");
        hm2.put("c","cc");
        hm2.putAll(hm);
        Set<String> keys1 = hm2.keySet();
        for(String key:keys1){
            System.out.println("key:"+key+"---value:"+hm2.get(key));
        }
        System.out.println("------删除操作------");
        String e = hm2.remove("e");
        Set<String> keys3 = hm2.keySet();
        for(String key:keys3){
            System.out.println("key:"+key+"---value:"+hm2.get(key));
        }
    }
}
